<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>设置一个偏移位置的值</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="arrayaccess.offsetget.html">« ArrayAccess::offsetGet</a></li>
      <li style="float: right;"><a href="arrayaccess.offsetunset.html">ArrayAccess::offsetUnset »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.arrayaccess.html">ArrayAccess</a></li>
    <li>设置一个偏移位置的值</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="arrayaccess.offsetset" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ArrayAccess::offsetSet</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ArrayAccess::offsetSet</span> &mdash; <span class="dc-title">设置一个偏移位置的值</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-arrayaccess.offsetset-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ArrayAccess::offsetSet</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$offset</code></span>, <span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><span class="type void">void</span></span></div>

  <p class="para rdfs-comment">
   为指定的偏移位置设置一个值。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-arrayaccess.offsetset-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">offset</code></dt>

     <dd>

      <p class="para">
       待设置的偏移位置。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">value</code></dt>

     <dd>

      <p class="para">
       需要设置的值。
      </p>
     </dd>

    
   </dl>

  </p>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-arrayaccess.offsetset-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   没有返回值。
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-arrayaccess.offsetset-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    如果另一个值不可用，那么 <code class="parameter">offset</code> 参数将被设置为 <strong><code>null</code></strong>，就像下面的例子。
    <div class="informalexample">
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$arrayaccess</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">"first&nbsp;value"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$arrayaccess</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">"second&nbsp;value"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$arrayaccess</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

     <p class="para">以上例程会输出：</p>
     <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [0] =&gt; first value
    [1] =&gt; second value
)
</pre></div>
     </div>
    </div>
   </p>
  </p></blockquote>

  <blockquote class="note"><p><strong class="note">注意</strong>: 
    <p class="para">
      This function is not called in assignments by reference and otherwise
      indirect changes to array dimensions overloaded with
      <span class="classname"><a href="class.arrayaccess.html" class="classname">ArrayAccess</a></span> (indirect in the sense they are
      made not by changing the dimension directly, but by changing a
      sub-dimension or sub-property or assigning the array dimension by
      reference to another variable).
      而是调用 <span class="function"><a href="arrayaccess.offsetget.html" class="function">ArrayAccess::offsetGet()</a></span>。 
      只有该方法通过引用返回，操作才会成功。
    </p>
  </p></blockquote>

 </div>




</div></div></div></body></html>